using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public class Util 
{
    public static void SetImgFullScreen(Image bg)
    {
        float spriteWidth = bg.sprite.textureRect.width;
        float spriteHeight = bg.sprite.textureRect.height;
        float aspectRatio = spriteWidth / spriteHeight;
        float screenWidth = Screen.width;
        float screenHeight = Screen.height;
        float aspectRatio2 = screenWidth / screenHeight;
        //Debug.Log($"{spriteWidth},{spriteHeight},{aspectRatio},{screenWidth},{screenHeight},{aspectRatio2}");
        if (aspectRatio2 > aspectRatio)
        {
            bg.rectTransform.sizeDelta = new Vector2(Screen.width, Screen.width / aspectRatio);
        }
        else
        {
            bg.rectTransform.sizeDelta = new Vector2(Screen.height * aspectRatio, Screen.height);
        }
    }
    static int score = 0;
    public static void AddScore(int value)
    {
        score += value;
        MainPanel.UpdateScore();
    }
    public static int Score
    {
        get
        {
            return score;
        }
    }
    public static void ClearScore()
    {
        score = 0;
        MainPanel.UpdateScore();
    }
    static MainPanel mainPanel;
    public static MainPanel MainPanel
    {
        get
        {
            if (mainPanel == null)
            {
                mainPanel = GameObject.Find("Canvas")?.GetComponent<MainPanel>();
            }
            return mainPanel;
        }
    }
    //static AudioSource audioTimer;
    //public static AudioSource AudioTimer
    //{
    //    get
    //    {
    //        if (audioTimer == null)
    //        {
    //            audioTimer = mainPanel.audio_Timer;
    //        }
    //        return audioTimer;
    //    }
    //}
    //static AudioSource audioCut;
    //public static AudioSource AudioCut
    //{
    //    get
    //    {
    //        if (audioCut == null)
    //        {
    //            audioCut = mainPanel.audio_Cut;
    //        }
    //        return audioCut;
    //    }
    //}
    public static void PlayCut()
    {
        H5Controller.PlayCut();
    }
    public static void PlayBtn()
    {
        H5Controller.PlayBtn();
    }
    public static void PlayTimer()
    {
        H5Controller.PlayTimer();
    }
}
